namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DmDtDataAccess
    {
        private WSDmDtDataAccess.WSDmDtDataAccess wDataAcess = new WSDmDtDataAccess.WSDmDtDataAccess();
        private SmartSoft.DAL.DmDtDataAccess oDataAcess = new SmartSoft.DAL.DmDtDataAccess();

        public DmDtDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public DataSet GetDataSet()
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet();
            }
            else
            {
                return oDataAcess.GetDataSet();
            }
        }

        public DataSet GetDataSet(string ps_Code)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet(ps_Code);
            }
            else
            {
                return oDataAcess.GetDataSet(ps_Code);
            }
        }

        public DataSet GetDataSetByParent(string ps_ParentCode, string ps_Ma_Dvcs)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSetByParent(ps_ParentCode, ps_Ma_Dvcs);
            }
            else
            {
                return oDataAcess.GetDataSetByParent(ps_ParentCode, ps_Ma_Dvcs);
            }
        }

        public int SaveRow(bool pb_NewChecked, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRow(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.SaveRow(pb_NewChecked, row);
            }
        }
    }
}

